import 'package:flutter/material.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/models/user/xindong_kongjian_user.dart';
import 'package:xindong/routes/userspace/xindong_kongjian_ctr.dart';
import 'package:xindong/routes/userspace/xindong_kongjian_photos_yemian.dart';
import 'package:xindong/routes/userspace/view/xindong_kongjian_title_container.dart';
import 'package:xindong/widgets/common/xindong_round_image.dart';
import 'package:xindong/widgets/image/browser/xindong_images_browser.dart';
import 'package:xindong/widgets/image/image_grid/xindong_image_grid_view.dart';

class XinDongKongJianInfoPhoto extends StatelessWidget {
  final XinDongSpaceUser model;

  const XinDongKongJianInfoPhoto({super.key, required this.model});

  @override
  Widget build(BuildContext context) {
    const double spacing = 8.0;
    final dataList = model.photo_show;
    if (dataList.isEmpty && !model.isSelf) {
      return const SizedBox();
    }
    return GestureDetector(
      onTap: model.isSelf ? () => XinDongPageSingleton.instance.pushYeMian(const XinDongKongJianPhotosYeMian()) : null,
      behavior: HitTestBehavior.opaque,
      child: XinDongKongJianTitleContainer(
        title: '个人相册（${dataList.length}）',
        children: [
          XinDongImageGridView(
            dataList: dataList,
            spacing: spacing,
            columns: 5,
            maxCount: 0,
            radius: 8.0,
            onTapAddition: model.isSelf ? XinDongKongJianCtr.to.uploadAlbum : null,
            itemBuilder: (BuildContext context, int index) {
              return GestureDetector(
                onTap: () => XinDongImagesBrowser.show(list: dataList, currentIndex: index),
                child: XinDongRoundImage(url: dataList[index]),
              );
            },
          ),
        ],
      ),
    );
  }
}
